
/*
'===============================================================================
'  HNG.Portal.BL.TblTinTucManager
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Text;

namespace HNG.Portal.BLL
{
    public class TblTinTucManager : TblTinTucManagerBase
    {
        SqlConnection Conn = new SqlConnection(HNG.LIB.Common.Connection.strConn);
        /// <summary>
        /// Purpose: Class constructor.
        /// </summary>
        public TblTinTucManager()
        {
            // Nothing for now.
        }

        public DataTable fe_ShowNameAndID(TblTinTucEntity _TblTinTucEntity)
        {
            System.Text.StringBuilder sbSql = new System.Text.StringBuilder();
            SqlParameter[] _SqlParameter = new SqlParameter[11];
            try
            {
                sbSql.Append("WITH tblTemp AS").Append("\n");
                sbSql.Append("(").Append("\n");
                sbSql.Append("SELECT ROW_NUMBER() OVER(ORDER BY ");
                sbSql.AppendFormat("ch.{0} ", string.IsNullOrEmpty(_TblTinTucEntity.SortExpression) ? "[ID]" : _TblTinTucEntity.SortExpression);
                sbSql.Append(string.IsNullOrEmpty(_TblTinTucEntity.SortDirection) ? " DESC" : _TblTinTucEntity.SortDirection);
                sbSql.Append(") AS RowNum,").Append("\n");
                sbSql.Append("  ch.[Id],").Append("\n");
                sbSql.Append("  ch.[TieuDe],").Append("\n");
                sbSql.Append("  ch.[DanhMucTinID],").Append("\n");
                sbSql.Append("  ch.[TenLoaiDanhMuc],").Append("\n");
                sbSql.Append("  ch.[NhomTinID],").Append("\n");
                sbSql.Append("  ch.[strKieuTin],").Append("\n");
                sbSql.Append("  ch.[Image],").Append("\n");
                sbSql.Append("  ch.[KieuTin],").Append("\n");
                sbSql.Append("  ch.[NgayDang],").Append("\n");
                sbSql.Append("  ch.[TrangThai]").Append("\n");
                sbSql.Append("  FROM").Append("\n");
                sbSql.Append("  tblTinTuc ch").Append("\n");
                sbSql.AppendFormat("  LEFT JOIN tblDanhMucTin dmt").Append("\n");
                sbSql.Append("  ON dmt.ID = ch.DanhMucTinID").Append("\n");
                sbSql.AppendFormat("  LEFT JOIN tblLang lng").Append("\n");
                sbSql.Append("  ON lng.ID = dmt.LangID").Append("\n");

                sbSql.Append("  WHERE").Append("\n");
                sbSql.Append("  1 = 1").Append("\n");

                if (!string.IsNullOrEmpty(_TblTinTucEntity.ID))
                {
                    _SqlParameter[0] = new SqlParameter("@ID", _TblTinTucEntity.ID);
                    sbSql.Append("  AND ch.[ID] LIKE @ID").Append("\n");

                }
                string strCon = _TblTinTucEntity.Condition;
                if (!string.IsNullOrEmpty(_TblTinTucEntity.Condition))
                {
                    sbSql.AppendFormat("  AND (ch.[TieuDe] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TomTat] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Mota] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Image] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[NgayDang] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinHot] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinNoiBat] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TruyCap] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[DanhMucTinID] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TrangThai] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR dmt.[TenDanhMuc] LIKE '%{0}%'", strCon).Append("\n");

                    sbSql.AppendFormat("  OR ch.[TieuDe] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TomTat] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Mota] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Image] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[NgayDang] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinHot] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinNoiBat] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TruyCap] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[DanhMucTinID] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TrangThai] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR dmt.[TenDanhMuc] LIKE N'%{0}%'", strCon).Append("\n");

                    sbSql.Append(")").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.LangId))
                {
                    _SqlParameter[1] = new SqlParameter("@LangId", _TblTinTucEntity.LangId);
                    sbSql.Append("  AND dmt.[LangId] LIKE @LangId").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.DM))
                {
                    _SqlParameter[2] = new SqlParameter("@DanhMucTinId", _TblTinTucEntity.DM);
                    sbSql.Append("  AND ch.[DanhMucTinId] LIKE @DanhMucTinId OR ch.[DanhMucTinId] IN (SELECT ID FROM tblDanhMucTin WHERE DanhMucCha = @DanhMucTinId)").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.strTinHot))
                {
                    _SqlParameter[3] = new SqlParameter("@TinHot", _TblTinTucEntity.TinHot);
                    sbSql.Append("  AND ch.[TinHot] LIKE @TinHot").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.strTinNoiBat))
                {
                    _SqlParameter[4] = new SqlParameter("@TinNoiBat", _TblTinTucEntity.TinNoiBat);
                    sbSql.Append("  AND ch.[TinNoiBat] LIKE @TinNoiBat").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.Status))
                {
                    _SqlParameter[5] = new SqlParameter("@TrangThai", _TblTinTucEntity.TrangThai);
                    sbSql.Append("  AND ch.[TrangThai] LIKE @TrangThai").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.strNhomTin))
                {
                    _SqlParameter[6] = new SqlParameter("@NhomTinID", _TblTinTucEntity.strNhomTin);
                    sbSql.Append("  AND ch.[NhomTinID] LIKE @NhomTinID").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.StrKieuTin))
                {
                    _SqlParameter[7] = new SqlParameter("@StrKieuTin", _TblTinTucEntity.StrKieuTin);
                    sbSql.Append("  AND ch.[StrKieuTin] LIKE @StrKieuTin").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.NhomTinId.ToString()))
                {
                    _SqlParameter[8] = new SqlParameter("@NhomTinId", _TblTinTucEntity.NhomTinId);
                    sbSql.Append("  AND ch.[NhomTinId] LIKE @NhomTinId").Append("\n");
                }

                if (System.DateTime.MinValue != _TblTinTucEntity.CreateDateFrom)
                {
                    _SqlParameter[9] = new SqlParameter("@CreateDateFrom", _TblTinTucEntity.CreateDateFrom);
                    sbSql.Append("  AND DATEDIFF(Minute, ch.[NgayDang], @CreateDateFrom) < 0").Append("\n");
                }

                if (System.DateTime.MinValue != _TblTinTucEntity.CreateDateTo)
                {
                    _SqlParameter[10] = new SqlParameter("@CreateDateTo", _TblTinTucEntity.CreateDateTo);
                    sbSql.Append("  AND DATEDIFF(Minute, ch.[NgayDang], @CreateDateTo) > 0").Append("\n");
                }


                sbSql.Append(")").Append("\n");
                sbSql.Append("SELECT *, (SELECT Max(RowNum) FROM tblTemp) TotalItems FROM tblTemp").Append("\n");
                sbSql.AppendFormat("WHERE RowNum BETWEEN {0} AND {1}", _TblTinTucEntity.StartIndex, _TblTinTucEntity.EndIndex).Append("\n");
            }
            catch { }
            return AE.SqlHelper.ExecuteDataTable(Conn, CommandType.Text, sbSql.ToString(), _SqlParameter);
        }

        public DataTable be_selectToGridView(TblTinTucEntity _TblTinTucEntity)
        {
            System.Text.StringBuilder sbSql = new System.Text.StringBuilder();
            SqlParameter[] _SqlParameter = new SqlParameter[9];
            try
            {
                sbSql.Append("WITH tblTemp AS").Append("\n");
                sbSql.Append("(").Append("\n");
                sbSql.Append("SELECT ROW_NUMBER() OVER(ORDER BY ");
                sbSql.AppendFormat("ch.{0} ", string.IsNullOrEmpty(_TblTinTucEntity.SortExpression) ? "[ID]" : _TblTinTucEntity.SortExpression);
                sbSql.Append(string.IsNullOrEmpty(_TblTinTucEntity.SortDirection) ? " DESC" : _TblTinTucEntity.SortDirection);
                sbSql.Append(") AS RowNum,").Append("\n");
                sbSql.Append("  ch.[Id],").Append("\n");
                sbSql.Append("  ch.[TieuDe],").Append("\n");
                sbSql.Append("  ch.[Image],").Append("\n");
                sbSql.Append("  ch.[NgayDang],").Append("\n");
                sbSql.Append("  ch.[TinNoiBat],").Append("\n");
                sbSql.Append("  ch.[DanhMucTinID],").Append("\n");
                sbSql.Append("  ch.[TrangThai],").Append("\n");
                sbSql.Append("  ch.[TenDanhMuc],").Append("\n");
                sbSql.Append("  ch.[TenLoaiDanhMuc]").Append("\n");
                sbSql.Append("  FROM").Append("\n");
                sbSql.Append("  tblTinTuc ch").Append("\n");
                sbSql.AppendFormat("  LEFT JOIN tblLang lng").Append("\n");
                sbSql.Append("  ON lng.ID = ch.LangID").Append("\n");
                sbSql.Append("  WHERE").Append("\n");
                sbSql.Append("  1 = 1").Append("\n");

                if (!string.IsNullOrEmpty(_TblTinTucEntity.ID))
                {
                    _SqlParameter[0] = new SqlParameter("@ID", _TblTinTucEntity.ID);
                    sbSql.Append("  AND ch.[ID] LIKE @ID").Append("\n");

                }
                string strCon = _TblTinTucEntity.Condition;
                if (!string.IsNullOrEmpty(_TblTinTucEntity.Condition))
                {
                    sbSql.AppendFormat("  AND (ch.[TieuDe] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TomTat] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Mota] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Image] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[NgayDang] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinHot] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinNoiBat] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TruyCap] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[DanhMucTinID] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TrangThai] LIKE '%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TenDanhMuc] LIKE '%{0}%'", strCon).Append("\n");

                    sbSql.AppendFormat("  OR ch.[TieuDe] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TomTat] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Mota] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[Image] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[NgayDang] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinHot] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TinNoiBat] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TruyCap] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[DanhMucTinID] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TrangThai] LIKE N'%{0}%'", strCon).Append("\n");
                    sbSql.AppendFormat("  OR ch.[TenDanhMuc] LIKE N'%{0}%'", strCon).Append("\n");

                    sbSql.Append(")").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.LangId))
                {
                    _SqlParameter[1] = new SqlParameter("@LangId", _TblTinTucEntity.LangId);
                    sbSql.Append("  AND ch.[LangID] LIKE @LangId").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.DM))
                {
                    _SqlParameter[2] = new SqlParameter("@DanhMucTinId", _TblTinTucEntity.DM);
                    sbSql.Append("  AND ch.[DanhMucTinId] LIKE @DanhMucTinId OR ch.[DanhMucTinId] IN (SELECT ID FROM tblDanhMucTin WHERE DanhMucCha = @DanhMucTinId)").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.strTinHot))
                {
                    _SqlParameter[3] = new SqlParameter("@TinHot", _TblTinTucEntity.TinHot);
                    sbSql.Append("  AND ch.[TinHot] LIKE @TinHot").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.strTinNoiBat))
                {
                    _SqlParameter[4] = new SqlParameter("@TinNoiBat", _TblTinTucEntity.TinNoiBat);
                    sbSql.Append("  AND ch.[TinNoiBat] LIKE @TinNoiBat").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.Status))
                {
                    _SqlParameter[5] = new SqlParameter("@TrangThai", _TblTinTucEntity.TrangThai);
                    sbSql.Append("  AND ch.[TrangThai] LIKE @TrangThai").Append("\n");
                }

                if (!string.IsNullOrEmpty(_TblTinTucEntity.strNhomTin))
                {
                    _SqlParameter[6] = new SqlParameter("@NhomTinID", _TblTinTucEntity.strNhomTin);
                    sbSql.Append("  AND ch.[NhomTinID] LIKE @NhomTinID").Append("\n");
                }
                if (System.DateTime.MinValue != _TblTinTucEntity.CreateDateFrom)
                {
                    _SqlParameter[7] = new SqlParameter("@CreateDateFrom", _TblTinTucEntity.CreateDateFrom);
                    sbSql.Append("  AND DATEDIFF(Minute, ch.[NgayDang], @CreateDateFrom) < 0").Append("\n");
                }

                if (System.DateTime.MinValue != _TblTinTucEntity.CreateDateTo)
                {
                    _SqlParameter[8] = new SqlParameter("@CreateDateTo", _TblTinTucEntity.CreateDateTo);
                    sbSql.Append("  AND DATEDIFF(Minute, ch.[NgayDang], @CreateDateTo) > 0").Append("\n");
                }
                sbSql.Append(")").Append("\n");
                sbSql.Append("SELECT *, (SELECT Max(RowNum) FROM tblTemp) TotalItems FROM tblTemp").Append("\n");
                sbSql.AppendFormat("WHERE RowNum BETWEEN {0} AND {1}", _TblTinTucEntity.StartIndex, _TblTinTucEntity.EndIndex).Append("\n");
            }
            catch { }
            return AE.SqlHelper.ExecuteDataTable(Conn, CommandType.Text, sbSql.ToString(), _SqlParameter);
        }

        public DataTable be_selectToDropdownlist(int CateID)
        {
            System.Text.StringBuilder sbSql = new System.Text.StringBuilder();
            SqlParameter[] _SqlParameter = new SqlParameter[1];
            try
            {
                sbSql.Append("SELECT ").Append("\n");
                sbSql.Append("  ch.[ID],").Append("\n");
                sbSql.Append("  ch.[TieuDe],").Append("\n");
                sbSql.Append("  ch.[TenDanhMuc]").Append("\n");
                sbSql.Append("  FROM").Append("\n");
                sbSql.Append("  tblTinTuc ch").Append("\n");
                sbSql.AppendFormat("  LEFT JOIN tblDanhMucTin dmt").Append("\n");
                sbSql.Append("  ON dmt.ID = ch.DanhMucTinID").Append("\n");
                sbSql.Append("  WHERE").Append("\n");
                sbSql.Append("  1 = 1").Append("\n");

                if (!string.IsNullOrEmpty(CateID.ToString()))
                {
                    _SqlParameter[0] = new SqlParameter("@DanhMucTinID", CateID);
                    sbSql.Append("  AND ch.[DanhMucTinID] LIKE @DanhMucTinID OR ch.[DanhMucTinID] IN (SELECT ID FROM tblDanhMucTin WHERE DanhMucCha = @DanhMucTinID)").Append("\n");
                }

            }
            catch { }
            return AE.SqlHelper.ExecuteDataTable(Conn, CommandType.Text, sbSql.ToString(), _SqlParameter);
        }

        public DataTable SelectCommonWithPaging(TblTinTucEntity _TblTinTucEntity, int pageNumber, int PageSize, out int TotalPage)
        {
            DataTable _dt = new DataTable();
            SqlParameter[] _SqlParameter = new SqlParameter[7];
            System.Text.StringBuilder sbSql = new System.Text.StringBuilder();
            string _TableName = "tblTinTuc ch";
            string FieldOrderBy = "ch.[ID] DESC";
            string FieldList = "";
            FieldList += "  ch.[Id],";
            FieldList += "  ch.[TieuDe],";
            FieldList += "  ch.[TomTat],";
            FieldList += "  ch.[Mota],";
            FieldList += "  ch.[Image],";
            FieldList += "  ch.[NhomTinID],";
            FieldList += "  ch.[NgayDang],";
            FieldList += "  ch.[TinHot],";
            FieldList += "  ch.[TinNoiBat],";
            FieldList += "  ch.[TruyCap],";
            FieldList += "  ch.[DanhMucTinID],";
            FieldList += "  ch.[TrangThai],";
            FieldList += "  lng.[Name] LangName,";
            FieldList += "  dmt.[TenDanhMuc]";

            sbSql.Append(" LEFT JOIN tblDanhMucTin dmt on ch.[DanhMucTinID] = dmt.[ID]");
            sbSql.Append(" LEFT JOIN tbllang lng on dmt.[LangID] = lng.[ID]");
            sbSql.Append(" WHERE 1=1 ");

            if (!string.IsNullOrEmpty(_TblTinTucEntity.ID))
            {
                sbSql.AppendFormat("  AND ch.[ID] LIKE {0}", _TblTinTucEntity.ID);
            }

            if (!string.IsNullOrEmpty(_TblTinTucEntity.Condition))
            {
                sbSql.AppendFormat("  AND ch.[TieuDe] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[TomTat] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[Mota] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[Image] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[NgayDang] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[TinHot] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[TinNoiBat] LIKE N'%' + {0} + '%')", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[TruyCap] LIKE N'%' + {0} + '%')", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[DanhMucTinID] LIKE N'%' + {0} + '%'", _TblTinTucEntity.Condition);
                sbSql.AppendFormat("  OR ch.[TrangThai] LIKE N'%' + {0} + '%')", _TblTinTucEntity.Condition);
            }

            //if (!string.IsNullOrEmpty(_TblTinTucEntity.LangId))
            //{

            //    sbSql.AppendFormat("  AND dmt.[LangId] LIKE '{0}'", _TblTinTucEntity.LangId);
            //}

            if (!string.IsNullOrEmpty(_TblTinTucEntity.DM))
            {

                sbSql.AppendFormat(" AND ch.[DanhMucTinID] = {0}", _TblTinTucEntity.DM);
                sbSql.AppendFormat(" OR ch.[DanhMucTinID] in (select ID from tblDanhMucTin where DanhMucCha = {0})", _TblTinTucEntity.DM);
            }


            if (!string.IsNullOrEmpty(_TblTinTucEntity.strTinHot))
            {
                sbSql.AppendFormat("  AND ch.[TinHot] LIKE {0}", _TblTinTucEntity.TinHot);
            }

            if (!string.IsNullOrEmpty(_TblTinTucEntity.strTinNoiBat))
            {
                sbSql.AppendFormat("  AND ch.[TinNoiBat] LIKE {0}", _TblTinTucEntity.TinNoiBat);
            }

            if (!string.IsNullOrEmpty(_TblTinTucEntity.Status))
            {
                sbSql.AppendFormat("  AND ch.[TrangThai] LIKE {0}", _TblTinTucEntity.Status);
            }

            if (!string.IsNullOrEmpty(_TblTinTucEntity.strNhomTin))
            {
                sbSql.AppendFormat("  AND ch.[NhomTinID] LIKE {0}", _TblTinTucEntity.strNhomTin);
            }

            //dung thu tu trong proc
            _SqlParameter[0] = new SqlParameter("@datasrc ", _TableName);
            _SqlParameter[1] = new SqlParameter("@orderBy", FieldOrderBy);
            _SqlParameter[2] = new SqlParameter("@fieldlist", FieldList);
            _SqlParameter[3] = new SqlParameter("@filter", sbSql.ToString());
            _SqlParameter[4] = new SqlParameter("@pageNum", pageNumber);
            _SqlParameter[5] = new SqlParameter("@pageSize", PageSize);
            _SqlParameter[6] = new SqlParameter("@TotalPage", SqlDbType.Int, 4);
            _SqlParameter[6].Direction = ParameterDirection.Output;

            //string abc = "exec Table_Paging_v3 '" + _TableName + "','" + FieldOrderBy + "','" + FieldList + "','" + sbSql.ToString() + "'," + pageNumber + "," + PageSize + ",";

            _dt = AE.SqlHelper.ExecuteDataTable(Conn, "Table_Paging_v3", _SqlParameter);
            TotalPage = Convert.ToInt32(_SqlParameter[6].Value.ToString());
            return _dt;
        }
        /// <summary>
        /// Lay tin moi nhat dc dang tren he thong
        /// </summary>
        /// <returns></returns>
        public DataTable sp_News_GetTop3()
        {
            DataTable List = new DataTable();
            try
            {
                List = AE.SqlHelper.ExecuteDataTable(Conn, CommandType.StoredProcedure, "sp_News_GetTop3");
            }
            catch { }
            return List;
        }
    }
}
